#include "expression.h"
#include <iostream>
#include "mulexpression.h"
#include <algorithm>

int main(int argc, char **argv)
{
	int asd[] = {72, 4, 32, 0, 50, 51};
	std::sort(asd, &asd[5]);
	std::cout << "Empty input will terminate the application" << std::endl << std::endl;
	while(true)
	{
		std::string input;
		std::cout << "=> ";
		std::getline(std::cin, input);
		if(input.empty())
			break;
		Expression *expression = NULL;
		try
		{
			Expression *expression = Expression::parse(input.c_str());

			std::cout << std::endl << "Infix:\t";
			expression->printInfix();
			std::cout << std::endl << "RPN:\t";
			expression->printRpn();
			std::cout << std::endl << "Result: " << expression->value() << std::endl;
		}
		catch(std::exception *ex)
		{
			std::cout << "Error: " << ex->what() << std::endl;
		}

		std::cout << std::endl;

		if(expression)
			delete expression;
	}

	return 0;
}